package com.hawk.eye.common.encipher;

import com.hawk.eye.common.utils.AesUtil;
import com.hawk.eye.common.utils.JsonUtil;

/**
 * @className: AesSecureProcessor
 * @description:
 * @author: salad
 * @date: 2023/9/17
 **/
@SuppressWarnings("all")
public class AesSecureProcessor implements ISecureProcessor {

    @Override
    public byte[] encrypt(Object value, String secretKey) {
        if (null == value) {
            return null;
        }
        if (value instanceof String) {
            return AesUtil.encrypt((String) value, secretKey);
        } else if (JsonUtil.isCanSerialize(value)) {
            return AesUtil.encrypt(JsonUtil.toJson(value), secretKey);
        } else {
            return null;
        }
    }

    @Override
    public byte[] decrypt(byte[] value, String secretKey) {
        return AesUtil.decrypt(value, secretKey);
    }


}
